package com.cl.short_video_java.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cl.short_video_java.pojo.VideoType;
import com.cl.short_video_java.pojo.VideoVideo;
import com.cl.short_video_java.service.VideoTypeService;
import com.cl.short_video_java.service.VideoVideoService;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author 付
 * @Date 2024-11-27 14:42
 * @Version 1.0
 * @description
 * @since 1.0
 */
@Component
@Slf4j
public class HobbyTask {
	@Autowired
	private VideoTypeService videoTypeService;
	@Autowired
	private VideoVideoService videoVideoService;

	//	@Scheduled(cron = "* * * 1 * ?")
	public void RecommendVideo() {

	}

	/**
	 * 更新标签的数量
	 */
	@Scheduled(cron = "0 0 0 * * *")
	public void updateTagCount() {
		log.info("分类标签数量统计开始==========================");
		List<VideoType> list = videoTypeService.list();
		for (VideoType videoType : list) {
			List<VideoVideo> list1 = videoVideoService.list(new QueryWrapper<VideoVideo>().like("tags", "," + videoType.getId() + ","));
			videoType.setSort(list1.size());
		}

		videoTypeService.saveOrUpdateBatch(list);
		log.info("分类标签数量统计结束==========================");
	}
}
